package api

import (
	"fmt"
	"time"
)

// 发送好友申请通知
func SendFriendRequestNotification(fromUserID, toUserID uint, requestNote string) error {
	notification := &Notification{
		Type:       "friend_request",
		FromUserID: fromUserID,
		ToUserID:   toUserID,
		Content:    fmt.Sprintf("用户 %d 向你发送了好友申请", fromUserID),
		Timestamp:  time.Now().Unix(),
		Extra: map[string]interface{}{
			"request_note": requestNote, // 好友申请附言
			"request_time": time.Now().Unix(),
		},
	}

	return SendNotificationToUser(toUserID, notification)
}

// 发送好友申请结果通知（同意或拒绝）
func SendFriendRequestResultNotification(applicantUserID, targetUserID uint, isAccepted bool) error {
	var notification *Notification

	if isAccepted {
		notification = &Notification{
			Type:       "friend_accept",
			FromUserID: targetUserID,    // 处理申请的用户
			ToUserID:   applicantUserID, // 发送给申请人
			Content:    fmt.Sprintf("用户 %d 同意了你的好友申请", applicantUserID),
			Timestamp:  time.Now().Unix(),
		}
	} else {
		notification = &Notification{
			Type:       "friend_reject",
			FromUserID: targetUserID,    // 处理申请的用户
			ToUserID:   applicantUserID, // 发送给申请人
			Content:    fmt.Sprintf("用户 %d 拒绝了你的好友申请", applicantUserID),
			Timestamp:  time.Now().Unix(),
		}
	}

	return SendNotificationToUser(targetUserID, notification)
}
